package com.crl.core.animation
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;

	public class BitmapAnimationPlayer extends AbstractAnimationPlayer
	{
		private var _flashRect:Rectangle;
		
		private var _bitmapdata:BitmapData;
		private var bitmap:Bitmap;
		public function BitmapAnimationPlayer(iw:int,ih:int)
		{
			super();
			
			_flashRect=new Rectangle();
			_flashRect.width=iw;
			_flashRect.height=ih;
			
			bitmap=new Bitmap();
			bitmap.scrollRect=_flashRect;
			addChild(bitmap);
		}
		
		public function load(path:String):void{
			var loader:Loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
			loader.load(new URLRequest(path));
		}
		
		
		public function set bitmapdata(value:BitmapData):void{
			_bitmapdata=value;
			bitmap.bitmapData=_bitmapdata;
		}
		
		private function completeHandler(event:Event):void{
			var bitmap:Bitmap=(event.target as LoaderInfo).content as Bitmap;
			
			bitmapdata=bitmap.bitmapData;
			
			this.dispatchEvent(event);
		}
		
		override protected function render(frameInfo:*):void{
			_flashRect.x=_flashRect.width*_currentFrame;
			bitmap.scrollRect=_flashRect;
		}
	}
}